<%@ page import="raojt.day0109.lotteryProject.dao.LotteryBusinessDao" %>
<%@ page import="raojt.day0109.lotteryProject.dao.impl.LotteryBusinessDaoImpl" %>
<%@ page import="raojt.day0109.lotteryProject.entity.User" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: 22770
  Date: 2023/1/9
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>保存用户信息</title>
    <%
        request.setCharacterEncoding("UTF-8");
        //获取addUser.jsp页面中，用户名和手机号
        String userName = request.getParameter("putName");
        String phone = request.getParameter("putPhone");

        //多态体现，创建数据访问层
        LotteryBusinessDao lotteryBusinessDao = new LotteryBusinessDaoImpl();

        User user = new User();
        user.setUserName(userName);
        //随机长度
        int num = (int)(8 + Math.random() * (11 - 8 + 1));
        String str = "abcdefghijklmnopqrstuvwxyz0123456789";
        int len = str.length();
        StringBuffer markNo = new StringBuffer();
        for (int i =0;i < num;i++){
            markNo.append(str.charAt((int) Math.round(Math.random() * (len - 1))));
        }
        user.setMarkNo(markNo.toString());
        user.setPhone(phone);
//        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
//        user.setOpenDate(sf.format(new Date()));
        int addRes = lotteryBusinessDao.addUser(user);
        if (addRes > 0){
            //跳转到index.jsp页面
            //转发 和 重定向
            request.getRequestDispatcher("lottery.jsp").forward(request,response);
        }else{
            out.print("添加失败");
        }
    %>
</head>
<body>

</body>
</html>
